package adapte

import android.os.Bundle
import androidx.activity.enableEdgeToEdge
import androidx.appcompat.app.AppCompatActivity
import androidx.core.view.ViewCompat
import androidx.core.view.WindowInsetsCompat
import androidx.recyclerview.widget.GridLayoutManager
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.example.day01.R
import com.example.demoone.Item
import com.example.demoone.MyAdapter

class activity_Activity : AppCompatActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        enableEdgeToEdge()
        setContentView(R.layout.activity_activity)
        ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main)) { v, insets ->
            val systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars())
            v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom)
            insets
        }
        val recyclerView = findViewById<RecyclerView>(R.id.recyclerView)
        recyclerView.layoutManager = LinearLayoutManager(this, RecyclerView.VERTICAL, false)

        // 创建20条模拟数据，格式为"黑马程序员 X"，其中X从1开始递增
//        val items = List(21) { i -> "黑马程序员 ${i + 1}" }
//        创建20条数据，类型为MyAdapter.Item
        
        val items = (0..20).map {
            Item(
                R.drawable.bj,
                "🏀🐔$it"
            )
        }


        // 设置自定义适配器MyAdapter，传入模拟数据列表
        recyclerView.adapter = MyAdapter(items)
    }
}